{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "<html>\n",
    "<h1> PTRAIL Spatial Features </h1>\n",
    "\n",
    "<p align='justify'>\n",
    "    This Jupyter notebook contains the examples of all the\n",
    "    spatial features available in PTRAIL library.\n",
    "    <br>\n",
    "    <br>\n",
    "    The notebook makes the use of three different datasets each\n",
    "    with different number of trajectory ids. This way the\n",
    "    running time of each feature is tested accordingly.\n",
    "    With the increase in the number of Trajectory ids, the\n",
    "    differences in running time are reflected as the code\n",
    "    utilizes all the available CPU cores of the computer for\n",
    "    parallel computation of features thus making these features\n",
    "    faster than the other comparable libraries providing the same\n",
    "    functionalities.\n",
    "</p>\n",
    "\n",
    "<hr>\n",
    "\n",
    "<p align='justify'>\n",
    "In this Jupyter Notebook containing Spatial examples, the following\n",
    "datasets are used:\n",
    "    <ul>\n",
    "        <li> <a href=\"https://github.com/YakshHaranwala/PTRAIL/blob/main/examples/data/geolife_sample.csv\" target=\"_blank\"> Geolife Sample </a> </li>\n",
    "        <li> <a href=\"https://github.com/YakshHaranwala/PTRAIL/blob/main/examples/data/gulls.csv\" target=\"_blank\"> Seagulls Dataset </a> </li>\n",
    "        <li> <a href=\"https://github.com/YakshHaranwala/PTRAIL/blob/main/examples/data/atlantic.csv\" target=\"_blank\"> Hurricane Dataset </a> </li>\n",
    "    </ul>\n",
    "</p>\n",
    "\n",
    "<hr>\n",
    "<p align='justify'>\n",
    "Note: Viewing this notebook in GitHub will not render JavaScript\n",
    "elements. Hence, for a better experience, click the link below\n",
    "to open the Jupyter notebook in NB viewer.\n",
    "\n",
    "<span> &#8618; </span>\n",
    "<a href=\"https://nbviewer.jupyter.org/github/YakshHaranwala/PTRAIL/blob/main/examples/2.%20spatial_examples.ipynb\" target='_blank'> Click Here </a>\n",
    "</p>\n",
    "</html>"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "code",
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "name": "#%%\n"
    }
   },
   "source": [
    "# First, lets import all the necessary modules that are required\n",
    "# for the functioning of the code contained in the jupyter notebook.\n",
    "\n",
    "import numpy as np\n",
    "from ptrail.core.TrajectoryDF import PTRAILDataFrame\n",
    "from ptrail.features.kinematic_features import KinematicFeatures as spatial\n",
    "from ptrail.utilities.conversions import Conversions as con\n",
    "import pandas as pd\n",
    "import time\n",
    "np.seterr(invalid='ignore')\n",
    "start = time.time()"
   ],
   "execution_count": 1,
   "outputs": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 506 ms, sys: 19.9 ms, total: 526 ms\n",
      "Wall time: 529 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon\ntraj_id DateTime                                  \n1       2008-10-23 05:53:11  39.984224  116.319402\n        2008-10-23 05:53:16  39.984211  116.319389\n        2008-10-23 05:53:21  39.984217  116.319422\n        2008-10-23 05:53:23  39.984710  116.319865\n        2008-10-23 05:53:28  39.984674  116.319810",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\"\"\"\n",
    "    First of all, lets import all the datasets one by one\n",
    "    and check out a few of their points.\n",
    "\"\"\"\n",
    "# Reading the geolife dataset and converting to PTRAILDataFrame.\n",
    "# Also, lets, print the first 5 points of the dataset to\n",
    "# see how the dataframe looks.\n",
    "geolife = pd.read_csv('./data/geolife_sample.csv')\n",
    "geolife = PTRAILDataFrame(geolife,'lat','lon','datetime','id')\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 264 ms, sys: 15.4 ms, total: 280 ms\n",
      "Wall time: 283 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \ntraj_id DateTime                                                                \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...  \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...  \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...  \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...  \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Reading the gulls dataset and converting to PTRAILDataFrame.\n",
    "# Also, lets, print the first 5 points of the dataset to\n",
    "# see how the dataframe looks.\n",
    "gulls = pd.read_csv('./data/gulls.csv')\n",
    "gulls = PTRAILDataFrame(gulls,\n",
    "                        latitude='location-lat',\n",
    "                        longitude='location-long',\n",
    "                        datetime='timestamp',\n",
    "                        traj_id='tag-local-identifier',\n",
    "                        rest_of_columns=[])\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 7.92 s, sys: 60.7 ms, total: 7.98 s\n",
      "Wall time: 7.98 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  Low Wind SW  \\\ntraj_id  DateTime                                            ...                \nAL011851 1851-06-25 00:00:00              -999         -999  ...         -999   \n         1851-06-25 06:00:00              -999         -999  ...         -999   \n         1851-06-25 12:00:00              -999         -999  ...         -999   \n         1851-06-25 18:00:00              -999         -999  ...         -999   \n         1851-06-25 21:00:00              -999         -999  ...         -999   \n\n                              Low Wind NW  Moderate Wind NE  Moderate Wind SE  \\\ntraj_id  DateTime                                                               \nAL011851 1851-06-25 00:00:00         -999              -999              -999   \n         1851-06-25 06:00:00         -999              -999              -999   \n         1851-06-25 12:00:00         -999              -999              -999   \n         1851-06-25 18:00:00         -999              -999              -999   \n         1851-06-25 21:00:00         -999              -999              -999   \n\n                              Moderate Wind SW  Moderate Wind NW  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              High Wind NE  High Wind SE  High Wind SW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                              High Wind NW  \ntraj_id  DateTime                           \nAL011851 1851-06-25 00:00:00          -999  \n         1851-06-25 06:00:00          -999  \n         1851-06-25 12:00:00          -999  \n         1851-06-25 18:00:00          -999  \n         1851-06-25 21:00:00          -999  \n\n[5 rows x 21 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Low Wind SW</th>\n      <th>Low Wind NW</th>\n      <th>Moderate Wind NE</th>\n      <th>Moderate Wind SE</th>\n      <th>Moderate Wind SW</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 21 columns</p>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "'''\n",
    "    1. Reading the atlantic dataset, cleaning it up and then\n",
    "       converting it to PTRAILDataFrame.\n",
    "    2. It is to be noted that apart from reading the dataset,\n",
    "       before converting to PTRAILDataFrame, the dataframe needs\n",
    "       some cleanup as the Time format provided in the dataframe\n",
    "       needs to be first converted into a library supported time\n",
    "       format. Also, the format of the coordinates need to be\n",
    "       converted to library supported format before converting'\n",
    "       it to PTRAILDataFrame.\n",
    "    3. Also, lets, print the first 5 points of the dataset to\n",
    "      see how the dataframe looks.\n",
    "'''\n",
    "atlantic = pd.read_csv('./data/atlantic.csv')\n",
    "atlantic = con.convert_directions_to_degree_lat_lon(atlantic, 'Latitude',\"Longitude\")\n",
    "def convert_to_datetime(row):\n",
    "        this_date = '{}-{}-{}'.format(str(row['Date'])[0:4], str(row['Date'])[4:6], str(row['Date'])[6:])\n",
    "        this_time = '{:02d}:{:02d}:00'.format(int(row['Time']/100), int(str(row['Time'])[-2:]))\n",
    "        return '{} {}'.format(this_date, this_time)\n",
    "atlantic['DateTime'] = atlantic.apply(convert_to_datetime, axis=1)\n",
    "atlantic = PTRAILDataFrame(atlantic,\n",
    "                           latitude='Latitude',\n",
    "                           longitude='Longitude',\n",
    "                           datetime='DateTime',\n",
    "                           traj_id='ID',\n",
    "                           rest_of_columns=[])\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(22.147577, 113.548843, 41.132062, 121.156224)\n",
      "(-62.71617, 4.02517, 65.2325, 103.19317)\n",
      "(7.2, -109.5, 81.0, 63.0)\n",
      "CPU times: user 6.23 ms, sys: 59 µs, total: 6.28 ms\n",
      "Wall time: 4.63 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the bounding boxes of all the dataframes.\n",
    "print(spatial.get_bounding_box(geolife))\n",
    "print(spatial.get_bounding_box(gulls))\n",
    "print(spatial.get_bounding_box(atlantic))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "               lat         lon\n",
      "traj_id                       \n",
      "1        39.984224  116.319402\n",
      "5        40.004155  116.321337\n",
      "              lat       lon\n",
      "traj_id                    \n",
      "91785    64.98267  35.74300\n",
      "91769    54.18433   7.91283\n",
      "91797    64.96767  35.73650\n",
      "91843    55.42533  49.34817\n",
      "91913    64.97850  35.72667\n",
      "...           ...       ...\n",
      "91814    55.43233  49.34283\n",
      "91763    62.78917  28.76983\n",
      "91823    54.18600   7.91867\n",
      "91752    62.40617  29.46983\n",
      "91916    54.18533   7.91500\n",
      "\n",
      "[126 rows x 2 columns]\n",
      "           lat   lon\n",
      "traj_id             \n",
      "AL031860  40.0 -50.5\n",
      "AL011858  19.0 -85.5\n",
      "AL011870  30.5 -88.0\n",
      "AL021851  22.2 -97.6\n",
      "AL051865  29.7 -92.0\n",
      "...        ...   ...\n",
      "AL041957  13.0 -21.3\n",
      "AL142012  15.5 -38.0\n",
      "AL201969  16.0 -47.0\n",
      "AL141971  25.5 -71.5\n",
      "AL031899  11.7 -31.0\n",
      "\n",
      "[1814 rows x 2 columns]\n",
      "CPU times: user 471 ms, sys: 372 ms, total: 843 ms\n",
      "Wall time: 5.24 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the start times of all the dataframes without\n",
    "# giving a traj_id.\n",
    "print(spatial.get_start_location(geolife))\n",
    "print(spatial.get_start_location(gulls))\n",
    "print(spatial.get_start_location(atlantic))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(39.984224, 116.319402)\n",
      "(61.24783, 24.58617)\n",
      "(28.0, -94.8)\n",
      "CPU times: user 122 ms, sys: 4.07 ms, total: 126 ms\n",
      "Wall time: 123 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the start times of all dataframes with a\n",
    "# traj_id.\n",
    "print(spatial.get_start_location(geolife, '1'))\n",
    "print(spatial.get_start_location(gulls, \"91732\"))\n",
    "print(spatial.get_start_location(atlantic, 'AL011851'))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "               lat         lon\n",
      "traj_id                       \n",
      "1        39.977879  116.326628\n",
      "5        39.999978  116.327460\n",
      "              lat       lon\n",
      "traj_id                    \n",
      "91785    64.98267  35.74300\n",
      "91769    54.18417   7.91350\n",
      "91797    64.96767  35.73633\n",
      "91843    55.43533  49.36383\n",
      "91913    64.96700  35.74083\n",
      "...           ...       ...\n",
      "91814    -1.79117  32.80583\n",
      "91763     6.97833  29.51200\n",
      "91823    61.31100  24.57767\n",
      "91752     8.06067  38.85033\n",
      "91916    56.56600  21.19633\n",
      "\n",
      "[126 rows x 2 columns]\n",
      "           lat   lon\n",
      "traj_id             \n",
      "AL031860  40.0 -50.5\n",
      "AL011858  19.0 -85.5\n",
      "AL011870  30.5 -88.0\n",
      "AL021851  22.2 -97.6\n",
      "AL051865  29.7 -92.0\n",
      "...        ...   ...\n",
      "AL041957  50.0  -6.0\n",
      "AL142012  37.6 -29.1\n",
      "AL201969  26.1 -61.6\n",
      "AL141971  35.7 -69.9\n",
      "AL031899  49.0 -15.5\n",
      "\n",
      "[1814 rows x 2 columns]\n",
      "CPU times: user 472 ms, sys: 449 ms, total: 921 ms\n",
      "Wall time: 5.36 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the start times of all the dataframes without\n",
    "# giving a traj_id.\n",
    "print(spatial.get_end_location(geolife))\n",
    "print(spatial.get_end_location(gulls))\n",
    "print(spatial.get_end_location(atlantic))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(39.977879, 116.326628)\n",
      "(31.09783, 29.81217)\n",
      "(31.0, -100.2)\n",
      "CPU times: user 109 ms, sys: 4.15 ms, total: 114 ms\n",
      "Wall time: 111 ms\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the start times of all dataframes with a traj_id.\n",
    "print(spatial.get_end_location(geolife, '1'))\n",
    "print(spatial.get_end_location(gulls, \"91732\"))\n",
    "print(spatial.get_end_location(atlantic, 'AL011851'))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 226 ms, sys: 8.24 ms, total: 234 ms\n",
      "Wall time: 232 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance\ntraj_id DateTime                                             \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN\n        2008-10-23 05:53:16  39.984211  116.319389   1.821083\n        2008-10-23 05:53:21  39.984217  116.319422   2.889671\n        2008-10-23 05:53:23  39.984710  116.319865  66.555997\n        2008-10-23 05:53:28  39.984674  116.319810   6.162987\n        2008-10-23 05:53:33  39.984623  116.319773   6.488225\n        2008-10-23 05:53:38  39.984606  116.319732   3.971848\n        2008-10-23 05:53:43  39.984555  116.319728   5.681172\n        2008-10-23 05:53:48  39.984579  116.319769   4.395924\n        2008-10-23 05:53:51  39.984579  116.319769   0.000000",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"10\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:33</th>\n      <td>39.984623</td>\n      <td>116.319773</td>\n      <td>6.488225</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:38</th>\n      <td>39.984606</td>\n      <td>116.319732</td>\n      <td>3.971848</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:43</th>\n      <td>39.984555</td>\n      <td>116.319728</td>\n      <td>5.681172</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:48</th>\n      <td>39.984579</td>\n      <td>116.319769</td>\n      <td>4.395924</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:51</th>\n      <td>39.984579</td>\n      <td>116.319769</td>\n      <td>0.000000</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the distance between 2 consecutive points for\n",
    "# each dataset one by one.\n",
    "# First, we will check the distances between 2 consecutive points\n",
    "# in the geolife dataset.\n",
    "geolife = spatial.create_distance_column(geolife)\n",
    "geolife.head(10)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 151 ms, sys: 64.1 ms, total: 215 ms\n",
      "Wall time: 400 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  \ntraj_id DateTime                          \n91732   2009-05-27 14:00:00          NaN  \n        2009-05-27 20:00:00  1699.244398  \n        2009-05-28 05:00:00  5632.120064  \n        2009-05-28 08:00:00  5643.314949  \n        2009-05-28 14:00:00    32.131494  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# # Here, we check the distance between 2 consecutive points\n",
    "# # in the seagulls dataset.\n",
    "gulls = spatial.create_distance_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 217 ms, sys: 88.4 ms, total: 305 ms\n",
      "Wall time: 637 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  Low Wind NW  \\\ntraj_id  DateTime                                            ...                \nAL011851 1851-06-25 00:00:00              -999         -999  ...         -999   \n         1851-06-25 06:00:00              -999         -999  ...         -999   \n         1851-06-25 12:00:00              -999         -999  ...         -999   \n         1851-06-25 18:00:00              -999         -999  ...         -999   \n         1851-06-25 21:00:00              -999         -999  ...         -999   \n\n                              Moderate Wind NE  Moderate Wind SE  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              Moderate Wind SW  Moderate Wind NW  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              High Wind NE  High Wind SE  High Wind SW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                              High Wind NW      Distance  \ntraj_id  DateTime                                         \nAL011851 1851-06-25 00:00:00          -999           NaN  \n         1851-06-25 06:00:00          -999  58907.516366  \n         1851-06-25 12:00:00          -999  58907.516366  \n         1851-06-25 18:00:00          -999  50310.976622  \n         1851-06-25 21:00:00          -999  31444.370265  \n\n[5 rows x 22 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Low Wind NW</th>\n      <th>Moderate Wind NE</th>\n      <th>Moderate Wind SE</th>\n      <th>Moderate Wind SW</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 22 columns</p>\n</div>"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Here, we check the distance between 2 consecutive points\n",
    "# in the atlantic dataset.\n",
    "atlantic = spatial.create_distance_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 222 ms, sys: 16.6 ms, total: 238 ms\n",
      "Wall time: 238 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  \ntraj_id DateTime                                  \n1       2008-10-23 05:53:11                  NaN  \n        2008-10-23 05:53:16             1.821083  \n        2008-10-23 05:53:21             1.873356  \n        2008-10-23 05:53:23            66.906656  \n        2008-10-23 05:53:28            60.927269  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the distance from start to current point for\n",
    "# each dataset one by one.\n",
    "# Here, we check the distance between start to all points\n",
    "# in the geolife dataset.\n",
    "\n",
    "geolife = spatial.create_distance_from_start_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 126 ms, sys: 91.8 ms, total: 218 ms\n",
      "Wall time: 425 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start  \ntraj_id DateTime                                               \n91732   2009-05-27 14:00:00          NaN                  NaN  \n        2009-05-27 20:00:00  1699.244398          1699.244398  \n        2009-05-28 05:00:00  5632.120064          7238.295521  \n        2009-05-28 08:00:00  5643.314949          1682.777895  \n        2009-05-28 14:00:00    32.131494          1697.111327  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Here, we check the distance between start to all points\n",
    "# in the seagulls dataset.\n",
    "gulls = spatial.create_distance_from_start_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 211 ms, sys: 93.2 ms, total: 304 ms\n",
      "Wall time: 699 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              Moderate Wind NE  Moderate Wind SE  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              Moderate Wind SW  Moderate Wind NW  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              High Wind NE  High Wind SE  High Wind SW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                              High Wind NW      Distance  Distance_from_start  \ntraj_id  DateTime                                                              \nAL011851 1851-06-25 00:00:00          -999           NaN                  NaN  \n         1851-06-25 06:00:00          -999  58907.516366         58907.516366  \n         1851-06-25 12:00:00          -999  58907.516366        117814.676769  \n         1851-06-25 18:00:00          -999  50310.976622        167196.061925  \n         1851-06-25 21:00:00          -999  31444.370265        197430.193137  \n\n[5 rows x 23 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Moderate Wind NE</th>\n      <th>Moderate Wind SE</th>\n      <th>Moderate Wind SW</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 23 columns</p>\n</div>"
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Here, we check the distance between start to all points\n",
    "# in the atlantic dataset.\n",
    "atlantic = spatial.create_distance_from_start_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 152 ms, sys: 413 µs, total: 152 ms\n",
      "Wall time: 150 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "21684.31604215524"
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Here, we are calculating the distance travelled in traj_id 1\n",
    "# on the date 2008-10-23.\n",
    "spatial.distance_travelled_by_date_and_traj_id(geolife,\n",
    "                                               '2008-10-23',\n",
    "                                               '1')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 317 ms, sys: 89.3 ms, total: 407 ms\n",
      "Wall time: 2.7 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \ntraj_id DateTime                                                        \n1       2008-10-23 05:53:11                  NaN          1.221588e+07  \n        2008-10-23 05:53:16             1.821083          1.221588e+07  \n        2008-10-23 05:53:21             1.873356          1.221588e+07  \n        2008-10-23 05:53:23            66.906656          1.221590e+07  \n        2008-10-23 05:53:28            60.927269          1.221589e+07  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets check the distance of all the points\n",
    "# in the geolife dataset from the coordinates (0, 0).\n",
    "geolife = spatial.create_distance_from_point_column(geolife,\n",
    "                                                    (0, 0))\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 322 ms, sys: 129 ms, total: 451 ms\n",
      "Wall time: 2.44 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m  \ntraj_id DateTime                                \n1       2008-10-23 05:53:11               True  \n        2008-10-23 05:53:16               True  \n        2008-10-23 05:53:21               True  \n        2008-10-23 05:53:23               True  \n        2008-10-23 05:53:28               True  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets check if all the points in the geolife dataset\n",
    "# are within 12000 KMs of the coordinates (0, 0).\n",
    "geolife = spatial.create_point_within_range_column(geolife,\n",
    "                                                   (0,0),\n",
    "                                                   15000000)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 222 ms, sys: 15.7 ms, total: 238 ms\n",
      "Wall time: 236 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  \ntraj_id DateTime                                           \n1       2008-10-23 05:53:11               True        NaN  \n        2008-10-23 05:53:16               True   0.364217  \n        2008-10-23 05:53:21               True   0.577934  \n        2008-10-23 05:53:23               True  33.277998  \n        2008-10-23 05:53:28               True   1.232597  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the speed of the object between 2\n",
    "# consecutive trajectory points.\n",
    "# First, we are doing in the geolife dataset.\n",
    "geolife = spatial.create_speed_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 83.7 ms, sys: 162 µs, total: 83.9 ms\n",
      "Wall time: 82.5 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              Moderate Wind SE  Moderate Wind SW  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              Moderate Wind NW  High Wind NE  High Wind SE  \\\ntraj_id  DateTime                                                            \nAL011851 1851-06-25 00:00:00              -999          -999          -999   \n         1851-06-25 06:00:00              -999          -999          -999   \n         1851-06-25 12:00:00              -999          -999          -999   \n         1851-06-25 18:00:00              -999          -999          -999   \n         1851-06-25 21:00:00              -999          -999          -999   \n\n                              High Wind SW  High Wind NW      Distance  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999           NaN   \n         1851-06-25 06:00:00          -999          -999  58907.516366   \n         1851-06-25 12:00:00          -999          -999  58907.516366   \n         1851-06-25 18:00:00          -999          -999  50310.976622   \n         1851-06-25 21:00:00          -999          -999  31444.370265   \n\n                              Distance_from_start     Speed  \ntraj_id  DateTime                                            \nAL011851 1851-06-25 00:00:00                  NaN       NaN  \n         1851-06-25 06:00:00         58907.516366  2.727200  \n         1851-06-25 12:00:00        117814.676769  2.727200  \n         1851-06-25 18:00:00        167196.061925  2.329212  \n         1851-06-25 21:00:00        197430.193137  2.911516  \n\n[5 rows x 24 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Moderate Wind SE</th>\n      <th>Moderate Wind SW</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 24 columns</p>\n</div>"
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets calculate the speed between 2 consecutive\n",
    "# points in the atlantic dataset.\n",
    "atlantic = spatial.create_speed_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 133 ms, sys: 77 µs, total: 133 ms\n",
      "Wall time: 132 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \ntraj_id DateTime                                                         \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN  \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669  \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831  \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529  \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets calculate the speed between 2 consecutive\n",
    "# points in the seagulls dataset.\n",
    "gulls = spatial.create_speed_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 20.2 ms, sys: 18 µs, total: 20.2 ms\n",
      "Wall time: 19.3 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  Acceleration  \ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11               True        NaN           NaN  \n        2008-10-23 05:53:16               True   0.364217           NaN  \n        2008-10-23 05:53:21               True   0.577934      0.042744  \n        2008-10-23 05:53:23               True  33.277998     16.350032  \n        2008-10-23 05:53:28               True   1.232597     -6.409080  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n      <td>0.042744</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n      <td>16.350032</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n      <td>-6.409080</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the acceleration of the object\n",
    "# between 2 consecutive points.\n",
    "# First, lets check for the geolife dataset.\n",
    "geolife = spatial.create_acceleration_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 14.5 ms, sys: 296 µs, total: 14.8 ms\n",
      "Wall time: 13.3 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN   \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669   \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831   \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529   \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488   \n\n                             Acceleration  \ntraj_id DateTime                           \n91732   2009-05-27 14:00:00           NaN  \n        2009-05-27 20:00:00           NaN  \n        2009-05-28 05:00:00      0.000003  \n        2009-05-28 08:00:00      0.000032  \n        2009-05-28 14:00:00     -0.000024  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n      <td>0.000003</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n      <td>0.000032</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n      <td>-0.000024</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the acceleration of the gulls dataset.\n",
    "gulls = spatial.create_acceleration_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 18.5 ms, sys: 0 ns, total: 18.5 ms\n",
      "Wall time: 17.1 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              Moderate Wind SW  Moderate Wind NW  \\\ntraj_id  DateTime                                                  \nAL011851 1851-06-25 00:00:00              -999              -999   \n         1851-06-25 06:00:00              -999              -999   \n         1851-06-25 12:00:00              -999              -999   \n         1851-06-25 18:00:00              -999              -999   \n         1851-06-25 21:00:00              -999              -999   \n\n                              High Wind NE  High Wind SE  High Wind SW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                              High Wind NW      Distance  Distance_from_start  \\\ntraj_id  DateTime                                                               \nAL011851 1851-06-25 00:00:00          -999           NaN                  NaN   \n         1851-06-25 06:00:00          -999  58907.516366         58907.516366   \n         1851-06-25 12:00:00          -999  58907.516366        117814.676769   \n         1851-06-25 18:00:00          -999  50310.976622        167196.061925   \n         1851-06-25 21:00:00          -999  31444.370265        197430.193137   \n\n                                 Speed  Acceleration  \ntraj_id  DateTime                                     \nAL011851 1851-06-25 00:00:00       NaN           NaN  \n         1851-06-25 06:00:00  2.727200           NaN  \n         1851-06-25 12:00:00  2.727200 -2.672759e-18  \n         1851-06-25 18:00:00  2.329212 -1.842537e-05  \n         1851-06-25 21:00:00  2.911516  5.391703e-05  \n\n[5 rows x 25 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Moderate Wind SW</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n      <td>-2.672759e-18</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n      <td>-1.842537e-05</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n      <td>5.391703e-05</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 25 columns</p>\n</div>"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the acceleration of the atlantic dataset.\n",
    "atlantic = spatial.create_acceleration_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 24.7 ms, sys: 78 µs, total: 24.8 ms\n",
      "Wall time: 22.8 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  Acceleration  \\\ntraj_id DateTime                                                          \n1       2008-10-23 05:53:11               True        NaN           NaN   \n        2008-10-23 05:53:16               True   0.364217           NaN   \n        2008-10-23 05:53:21               True   0.577934      0.042744   \n        2008-10-23 05:53:23               True  33.277998     16.350032   \n        2008-10-23 05:53:28               True   1.232597     -6.409080   \n\n                                 Jerk  \ntraj_id DateTime                       \n1       2008-10-23 05:53:11       NaN  \n        2008-10-23 05:53:16       NaN  \n        2008-10-23 05:53:21       NaN  \n        2008-10-23 05:53:23  8.153644  \n        2008-10-23 05:53:28 -4.551822  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n      <td>0.042744</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n      <td>16.350032</td>\n      <td>8.153644</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n      <td>-6.409080</td>\n      <td>-4.551822</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the jerk of the object between 2 consecutive\n",
    "# points.\n",
    "# First, we will do it for the geolife dataset.\n",
    "geolife = spatial.create_jerk_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 11.7 ms, sys: 0 ns, total: 11.7 ms\n",
      "Wall time: 10.5 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              Moderate Wind NW  High Wind NE  High Wind SE  \\\ntraj_id  DateTime                                                            \nAL011851 1851-06-25 00:00:00              -999          -999          -999   \n         1851-06-25 06:00:00              -999          -999          -999   \n         1851-06-25 12:00:00              -999          -999          -999   \n         1851-06-25 18:00:00              -999          -999          -999   \n         1851-06-25 21:00:00              -999          -999          -999   \n\n                              High Wind SW  High Wind NW      Distance  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999           NaN   \n         1851-06-25 06:00:00          -999          -999  58907.516366   \n         1851-06-25 12:00:00          -999          -999  58907.516366   \n         1851-06-25 18:00:00          -999          -999  50310.976622   \n         1851-06-25 21:00:00          -999          -999  31444.370265   \n\n                              Distance_from_start     Speed  Acceleration  \\\ntraj_id  DateTime                                                           \nAL011851 1851-06-25 00:00:00                  NaN       NaN           NaN   \n         1851-06-25 06:00:00         58907.516366  2.727200           NaN   \n         1851-06-25 12:00:00        117814.676769  2.727200 -2.672759e-18   \n         1851-06-25 18:00:00        167196.061925  2.329212 -1.842537e-05   \n         1851-06-25 21:00:00        197430.193137  2.911516  5.391703e-05   \n\n                                      Jerk  \ntraj_id  DateTime                           \nAL011851 1851-06-25 00:00:00           NaN  \n         1851-06-25 06:00:00           NaN  \n         1851-06-25 12:00:00           NaN  \n         1851-06-25 18:00:00 -8.530263e-10  \n         1851-06-25 21:00:00  6.698370e-09  \n\n[5 rows x 26 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>Moderate Wind NW</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n      <td>-2.672759e-18</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n      <td>-1.842537e-05</td>\n      <td>-8.530263e-10</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n      <td>5.391703e-05</td>\n      <td>6.698370e-09</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 26 columns</p>\n</div>"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the jerk for the atlantic dataset.\n",
    "atlantic = spatial.create_jerk_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 22.9 ms, sys: 0 ns, total: 22.9 ms\n",
      "Wall time: 20.7 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN   \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669   \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831   \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529   \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488   \n\n                             Acceleration          Jerk  \ntraj_id DateTime                                         \n91732   2009-05-27 14:00:00           NaN           NaN  \n        2009-05-27 20:00:00           NaN           NaN  \n        2009-05-28 05:00:00      0.000003           NaN  \n        2009-05-28 08:00:00      0.000032  2.717572e-09  \n        2009-05-28 14:00:00     -0.000024 -2.611536e-09  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n      <td>0.000003</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n      <td>0.000032</td>\n      <td>2.717572e-09</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n      <td>-0.000024</td>\n      <td>-2.611536e-09</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets check the jerk for the seagulls dataset.\n",
    "gulls = spatial.create_jerk_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 401 ms, sys: 11.3 ms, total: 412 ms\n",
      "Wall time: 410 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  Acceleration  \\\ntraj_id DateTime                                                          \n1       2008-10-23 05:53:11               True        NaN           NaN   \n        2008-10-23 05:53:16               True   0.364217           NaN   \n        2008-10-23 05:53:21               True   0.577934      0.042744   \n        2008-10-23 05:53:23               True  33.277998     16.350032   \n        2008-10-23 05:53:28               True   1.232597     -6.409080   \n\n                                 Jerk     Bearing  \ntraj_id DateTime                                   \n1       2008-10-23 05:53:11       NaN         NaN  \n        2008-10-23 05:53:16       NaN  217.460115  \n        2008-10-23 05:53:21       NaN   76.651056  \n        2008-10-23 05:53:23  8.153644   34.547615  \n        2008-10-23 05:53:28 -4.551822  229.494179  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>217.460115</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n      <td>0.042744</td>\n      <td>NaN</td>\n      <td>76.651056</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n      <td>16.350032</td>\n      <td>8.153644</td>\n      <td>34.547615</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n      <td>-6.409080</td>\n      <td>-4.551822</td>\n      <td>229.494179</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the bearing between 2 consecutive\n",
    "# points.\n",
    "# First, we will do it for the geolife dataset.\n",
    "geolife = spatial.create_bearing_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 574 ms, sys: 128 ms, total: 702 ms\n",
      "Wall time: 1.44 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              High Wind NE  High Wind SE  High Wind SW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                              High Wind NW      Distance  Distance_from_start  \\\ntraj_id  DateTime                                                               \nAL011851 1851-06-25 00:00:00          -999           NaN                  NaN   \n         1851-06-25 06:00:00          -999  58907.516366         58907.516366   \n         1851-06-25 12:00:00          -999  58907.516366        117814.676769   \n         1851-06-25 18:00:00          -999  50310.976622        167196.061925   \n         1851-06-25 21:00:00          -999  31444.370265        197430.193137   \n\n                                 Speed  Acceleration          Jerk     Bearing  \ntraj_id  DateTime                                                               \nAL011851 1851-06-25 00:00:00       NaN           NaN           NaN         NaN  \n         1851-06-25 06:00:00  2.727200           NaN           NaN  270.140842  \n         1851-06-25 12:00:00  2.727200 -2.672759e-18           NaN  270.140842  \n         1851-06-25 18:00:00  2.329212 -1.842537e-05 -8.530263e-10  282.886140  \n         1851-06-25 21:00:00  2.911516  5.391703e-05  6.698370e-09  290.779865  \n\n[5 rows x 27 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>High Wind NE</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n      <td>-2.672759e-18</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n      <td>-1.842537e-05</td>\n      <td>-8.530263e-10</td>\n      <td>282.886140</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n      <td>5.391703e-05</td>\n      <td>6.698370e-09</td>\n      <td>290.779865</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 27 columns</p>\n</div>"
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the bearing for the atlantic dataset.\n",
    "atlantic = spatial.create_bearing_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 301 ms, sys: 124 ms, total: 425 ms\n",
      "Wall time: 770 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN   \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669   \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831   \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529   \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488   \n\n                             Acceleration          Jerk     Bearing  \ntraj_id DateTime                                                     \n91732   2009-05-27 14:00:00           NaN           NaN         NaN  \n        2009-05-27 20:00:00           NaN           NaN  187.236713  \n        2009-05-28 05:00:00      0.000003           NaN  208.929407  \n        2009-05-28 08:00:00      0.000032  2.717572e-09   28.716637  \n        2009-05-28 14:00:00     -0.000024 -2.611536e-09  123.620959  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>187.236713</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n      <td>0.000003</td>\n      <td>NaN</td>\n      <td>208.929407</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n      <td>0.000032</td>\n      <td>2.717572e-09</td>\n      <td>28.716637</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n      <td>-0.000024</td>\n      <td>-2.611536e-09</td>\n      <td>123.620959</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets check the bearing for the seagulls dataset.\n",
    "gulls = spatial.create_bearing_column(gulls)\n",
    "gulls.head()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 23.4 ms, sys: 0 ns, total: 23.4 ms\n",
      "Wall time: 22.1 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  Acceleration  \\\ntraj_id DateTime                                                          \n1       2008-10-23 05:53:11               True        NaN           NaN   \n        2008-10-23 05:53:16               True   0.364217           NaN   \n        2008-10-23 05:53:21               True   0.577934      0.042744   \n        2008-10-23 05:53:23               True  33.277998     16.350032   \n        2008-10-23 05:53:28               True   1.232597     -6.409080   \n\n                                 Jerk     Bearing  Bearing_Rate  \ntraj_id DateTime                                                 \n1       2008-10-23 05:53:11       NaN         NaN           NaN  \n        2008-10-23 05:53:16       NaN  217.460115           NaN  \n        2008-10-23 05:53:21       NaN   76.651056    -28.161812  \n        2008-10-23 05:53:23  8.153644   34.547615    -21.051721  \n        2008-10-23 05:53:28 -4.551822  229.494179     38.989313  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>217.460115</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n      <td>0.042744</td>\n      <td>NaN</td>\n      <td>76.651056</td>\n      <td>-28.161812</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n      <td>16.350032</td>\n      <td>8.153644</td>\n      <td>34.547615</td>\n      <td>-21.051721</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n      <td>-6.409080</td>\n      <td>-4.551822</td>\n      <td>229.494179</td>\n      <td>38.989313</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the bearing rate between 2 consecutive points.\n",
    "# First, we will do it for the geolife dataset.\n",
    "geolife = spatial.create_bearing_rate_column(geolife)\n",
    "geolife.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 12.9 ms, sys: 0 ns, total: 12.9 ms\n",
      "Wall time: 11.2 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              High Wind SE  High Wind SW  High Wind NW  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999          -999   \n         1851-06-25 06:00:00          -999          -999          -999   \n         1851-06-25 12:00:00          -999          -999          -999   \n         1851-06-25 18:00:00          -999          -999          -999   \n         1851-06-25 21:00:00          -999          -999          -999   \n\n                                  Distance  Distance_from_start     Speed  \\\ntraj_id  DateTime                                                           \nAL011851 1851-06-25 00:00:00           NaN                  NaN       NaN   \n         1851-06-25 06:00:00  58907.516366         58907.516366  2.727200   \n         1851-06-25 12:00:00  58907.516366        117814.676769  2.727200   \n         1851-06-25 18:00:00  50310.976622        167196.061925  2.329212   \n         1851-06-25 21:00:00  31444.370265        197430.193137  2.911516   \n\n                              Acceleration          Jerk     Bearing  \\\ntraj_id  DateTime                                                      \nAL011851 1851-06-25 00:00:00           NaN           NaN         NaN   \n         1851-06-25 06:00:00           NaN           NaN  270.140842   \n         1851-06-25 12:00:00 -2.672759e-18           NaN  270.140842   \n         1851-06-25 18:00:00 -1.842537e-05 -8.530263e-10  282.886140   \n         1851-06-25 21:00:00  5.391703e-05  6.698370e-09  290.779865   \n\n                              Bearing_Rate  \ntraj_id  DateTime                           \nAL011851 1851-06-25 00:00:00           NaN  \n         1851-06-25 06:00:00           NaN  \n         1851-06-25 12:00:00      0.000000  \n         1851-06-25 18:00:00      0.000590  \n         1851-06-25 21:00:00      0.000731  \n\n[5 rows x 28 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>High Wind SE</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n      <td>-2.672759e-18</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n      <td>-1.842537e-05</td>\n      <td>-8.530263e-10</td>\n      <td>282.886140</td>\n      <td>0.000590</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n      <td>5.391703e-05</td>\n      <td>6.698370e-09</td>\n      <td>290.779865</td>\n      <td>0.000731</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 28 columns</p>\n</div>"
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets calculate the bearing rate for the atlantic dataset.\n",
    "atlantic = spatial.create_bearing_rate_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 10.9 ms, sys: 3.88 ms, total: 14.8 ms\n",
      "Wall time: 13.1 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN   \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669   \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831   \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529   \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488   \n\n                             Acceleration          Jerk     Bearing  \\\ntraj_id DateTime                                                      \n91732   2009-05-27 14:00:00           NaN           NaN         NaN   \n        2009-05-27 20:00:00           NaN           NaN  187.236713   \n        2009-05-28 05:00:00      0.000003           NaN  208.929407   \n        2009-05-28 08:00:00      0.000032  2.717572e-09   28.716637   \n        2009-05-28 14:00:00     -0.000024 -2.611536e-09  123.620959   \n\n                             Bearing_Rate  \ntraj_id DateTime                           \n91732   2009-05-27 14:00:00           NaN  \n        2009-05-27 20:00:00           NaN  \n        2009-05-28 05:00:00      0.000670  \n        2009-05-28 08:00:00     -0.016686  \n        2009-05-28 14:00:00      0.004394  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>187.236713</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n      <td>0.000003</td>\n      <td>NaN</td>\n      <td>208.929407</td>\n      <td>0.000670</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n      <td>0.000032</td>\n      <td>2.717572e-09</td>\n      <td>28.716637</td>\n      <td>-0.016686</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n      <td>-0.000024</td>\n      <td>-2.611536e-09</td>\n      <td>123.620959</td>\n      <td>0.004394</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets calculate the bearing rate for the seagulls dataset.\n",
    "gulls = spatial.create_bearing_rate_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 51.4 ms, sys: 4.42 ms, total: 55.9 ms\n",
      "Wall time: 54.3 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                   lat         lon   Distance  \\\ntraj_id DateTime                                                \n1       2008-10-23 05:53:11  39.984224  116.319402        NaN   \n        2008-10-23 05:53:16  39.984211  116.319389   1.821083   \n        2008-10-23 05:53:21  39.984217  116.319422   2.889671   \n        2008-10-23 05:53:23  39.984710  116.319865  66.555997   \n        2008-10-23 05:53:28  39.984674  116.319810   6.162987   \n\n                             Distance_from_start  Distance_from_(0, 0)  \\\ntraj_id DateTime                                                         \n1       2008-10-23 05:53:11                  NaN          1.221588e+07   \n        2008-10-23 05:53:16             1.821083          1.221588e+07   \n        2008-10-23 05:53:21             1.873356          1.221588e+07   \n        2008-10-23 05:53:23            66.906656          1.221590e+07   \n        2008-10-23 05:53:28            60.927269          1.221589e+07   \n\n                             Within_15000000_m      Speed  Acceleration  \\\ntraj_id DateTime                                                          \n1       2008-10-23 05:53:11               True        NaN           NaN   \n        2008-10-23 05:53:16               True   0.364217           NaN   \n        2008-10-23 05:53:21               True   0.577934      0.042744   \n        2008-10-23 05:53:23               True  33.277998     16.350032   \n        2008-10-23 05:53:28               True   1.232597     -6.409080   \n\n                                 Jerk     Bearing  Bearing_Rate  \\\ntraj_id DateTime                                                  \n1       2008-10-23 05:53:11       NaN         NaN           NaN   \n        2008-10-23 05:53:16       NaN  217.460115           NaN   \n        2008-10-23 05:53:21       NaN   76.651056    -28.161812   \n        2008-10-23 05:53:23  8.153644   34.547615    -21.051721   \n        2008-10-23 05:53:28 -4.551822  229.494179     38.989313   \n\n                             Rate_of_bearing_rate  \ntraj_id DateTime                                   \n1       2008-10-23 05:53:11                   NaN  \n        2008-10-23 05:53:16                   NaN  \n        2008-10-23 05:53:21            -28.161812  \n        2008-10-23 05:53:23            -21.051721  \n        2008-10-23 05:53:28             38.989313  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Distance_from_(0, 0)</th>\n      <th>Within_15000000_m</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n      <th>Rate_of_bearing_rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">1</th>\n      <th>2008-10-23 05:53:11</th>\n      <td>39.984224</td>\n      <td>116.319402</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:16</th>\n      <td>39.984211</td>\n      <td>116.319389</td>\n      <td>1.821083</td>\n      <td>1.821083</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.364217</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>217.460115</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:21</th>\n      <td>39.984217</td>\n      <td>116.319422</td>\n      <td>2.889671</td>\n      <td>1.873356</td>\n      <td>1.221588e+07</td>\n      <td>True</td>\n      <td>0.577934</td>\n      <td>0.042744</td>\n      <td>NaN</td>\n      <td>76.651056</td>\n      <td>-28.161812</td>\n      <td>-28.161812</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:23</th>\n      <td>39.984710</td>\n      <td>116.319865</td>\n      <td>66.555997</td>\n      <td>66.906656</td>\n      <td>1.221590e+07</td>\n      <td>True</td>\n      <td>33.277998</td>\n      <td>16.350032</td>\n      <td>8.153644</td>\n      <td>34.547615</td>\n      <td>-21.051721</td>\n      <td>-21.051721</td>\n    </tr>\n    <tr>\n      <th>2008-10-23 05:53:28</th>\n      <td>39.984674</td>\n      <td>116.319810</td>\n      <td>6.162987</td>\n      <td>60.927269</td>\n      <td>1.221589e+07</td>\n      <td>True</td>\n      <td>1.232597</td>\n      <td>-6.409080</td>\n      <td>-4.551822</td>\n      <td>229.494179</td>\n      <td>38.989313</td>\n      <td>38.989313</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the rate of bearing rate between 2\n",
    "# consecutive points.\n",
    "geolife = spatial.create_rate_of_br_column(geolife)\n",
    "geolife.head()\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 27.2 ms, sys: 0 ns, total: 27.2 ms\n",
      "Wall time: 25.7 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                                             Name      Date  Time Event  \\\ntraj_id  DateTime                                                         \nAL011851 1851-06-25 00:00:00              UNNAMED  18510625     0         \n         1851-06-25 06:00:00              UNNAMED  18510625   600         \n         1851-06-25 12:00:00              UNNAMED  18510625  1200         \n         1851-06-25 18:00:00              UNNAMED  18510625  1800         \n         1851-06-25 21:00:00              UNNAMED  18510625  2100     L   \n\n                             Status   lat   lon  Maximum Wind  \\\ntraj_id  DateTime                                               \nAL011851 1851-06-25 00:00:00     HU  28.0 -94.8            80   \n         1851-06-25 06:00:00     HU  28.0 -95.4            80   \n         1851-06-25 12:00:00     HU  28.0 -96.0            80   \n         1851-06-25 18:00:00     HU  28.1 -96.5            80   \n         1851-06-25 21:00:00     HU  28.2 -96.8            80   \n\n                              Minimum Pressure  Low Wind NE  ...  \\\ntraj_id  DateTime                                            ...   \nAL011851 1851-06-25 00:00:00              -999         -999  ...   \n         1851-06-25 06:00:00              -999         -999  ...   \n         1851-06-25 12:00:00              -999         -999  ...   \n         1851-06-25 18:00:00              -999         -999  ...   \n         1851-06-25 21:00:00              -999         -999  ...   \n\n                              High Wind SW  High Wind NW      Distance  \\\ntraj_id  DateTime                                                        \nAL011851 1851-06-25 00:00:00          -999          -999           NaN   \n         1851-06-25 06:00:00          -999          -999  58907.516366   \n         1851-06-25 12:00:00          -999          -999  58907.516366   \n         1851-06-25 18:00:00          -999          -999  50310.976622   \n         1851-06-25 21:00:00          -999          -999  31444.370265   \n\n                              Distance_from_start     Speed  Acceleration  \\\ntraj_id  DateTime                                                           \nAL011851 1851-06-25 00:00:00                  NaN       NaN           NaN   \n         1851-06-25 06:00:00         58907.516366  2.727200           NaN   \n         1851-06-25 12:00:00        117814.676769  2.727200 -2.672759e-18   \n         1851-06-25 18:00:00        167196.061925  2.329212 -1.842537e-05   \n         1851-06-25 21:00:00        197430.193137  2.911516  5.391703e-05   \n\n                                      Jerk     Bearing  Bearing_Rate  \\\ntraj_id  DateTime                                                      \nAL011851 1851-06-25 00:00:00           NaN         NaN           NaN   \n         1851-06-25 06:00:00           NaN  270.140842           NaN   \n         1851-06-25 12:00:00           NaN  270.140842      0.000000   \n         1851-06-25 18:00:00 -8.530263e-10  282.886140      0.000590   \n         1851-06-25 21:00:00  6.698370e-09  290.779865      0.000731   \n\n                              Rate_of_bearing_rate  \ntraj_id  DateTime                                   \nAL011851 1851-06-25 00:00:00                   NaN  \n         1851-06-25 06:00:00                   NaN  \n         1851-06-25 12:00:00              0.000000  \n         1851-06-25 18:00:00              0.000590  \n         1851-06-25 21:00:00              0.000731  \n\n[5 rows x 29 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>Name</th>\n      <th>Date</th>\n      <th>Time</th>\n      <th>Event</th>\n      <th>Status</th>\n      <th>lat</th>\n      <th>lon</th>\n      <th>Maximum Wind</th>\n      <th>Minimum Pressure</th>\n      <th>Low Wind NE</th>\n      <th>...</th>\n      <th>High Wind SW</th>\n      <th>High Wind NW</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n      <th>Rate_of_bearing_rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">AL011851</th>\n      <th>1851-06-25 00:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>0</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-94.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 06:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>600</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-95.4</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>58907.516366</td>\n      <td>2.727200</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 12:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1200</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.0</td>\n      <td>-96.0</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>58907.516366</td>\n      <td>117814.676769</td>\n      <td>2.727200</td>\n      <td>-2.672759e-18</td>\n      <td>NaN</td>\n      <td>270.140842</td>\n      <td>0.000000</td>\n      <td>0.000000</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 18:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>1800</td>\n      <td></td>\n      <td>HU</td>\n      <td>28.1</td>\n      <td>-96.5</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>50310.976622</td>\n      <td>167196.061925</td>\n      <td>2.329212</td>\n      <td>-1.842537e-05</td>\n      <td>-8.530263e-10</td>\n      <td>282.886140</td>\n      <td>0.000590</td>\n      <td>0.000590</td>\n    </tr>\n    <tr>\n      <th>1851-06-25 21:00:00</th>\n      <td>UNNAMED</td>\n      <td>18510625</td>\n      <td>2100</td>\n      <td>L</td>\n      <td>HU</td>\n      <td>28.2</td>\n      <td>-96.8</td>\n      <td>80</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>...</td>\n      <td>-999</td>\n      <td>-999</td>\n      <td>31444.370265</td>\n      <td>197430.193137</td>\n      <td>2.911516</td>\n      <td>5.391703e-05</td>\n      <td>6.698370e-09</td>\n      <td>290.779865</td>\n      <td>0.000731</td>\n      <td>0.000731</td>\n    </tr>\n  </tbody>\n</table>\n<p>5 rows × 29 columns</p>\n</div>"
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets calculate the rate of bearing rate for the atlantic\n",
    "# dataset.\n",
    "atlantic = spatial.create_rate_of_br_column(atlantic)\n",
    "atlantic.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 36.9 ms, sys: 88 µs, total: 37 ms\n",
      "Wall time: 35.1 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "                               event-id  visible       lon       lat  \\\ntraj_id DateTime                                                       \n91732   2009-05-27 14:00:00  1082620685     True  24.58617  61.24783   \n        2009-05-27 20:00:00  1082620686     True  24.58217  61.23267   \n        2009-05-28 05:00:00  1082620687     True  24.53133  61.18833   \n        2009-05-28 08:00:00  1082620688     True  24.58200  61.23283   \n        2009-05-28 14:00:00  1082620689     True  24.58250  61.23267   \n\n                            sensor-type individual-taxon-canonical-name  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00         gps                    Larus fuscus   \n        2009-05-27 20:00:00         gps                    Larus fuscus   \n        2009-05-28 05:00:00         gps                    Larus fuscus   \n        2009-05-28 08:00:00         gps                    Larus fuscus   \n        2009-05-28 14:00:00         gps                    Larus fuscus   \n\n                            individual-local-identifier  \\\ntraj_id DateTime                                          \n91732   2009-05-27 14:00:00                      91732A   \n        2009-05-27 20:00:00                      91732A   \n        2009-05-28 05:00:00                      91732A   \n        2009-05-28 08:00:00                      91732A   \n        2009-05-28 14:00:00                      91732A   \n\n                                                                    study-name  \\\ntraj_id DateTime                                                                 \n91732   2009-05-27 14:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-27 20:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 05:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 08:00:00  Navigation experiments in lesser black-backed ...   \n        2009-05-28 14:00:00  Navigation experiments in lesser black-backed ...   \n\n                                Distance  Distance_from_start     Speed  \\\ntraj_id DateTime                                                          \n91732   2009-05-27 14:00:00          NaN                  NaN       NaN   \n        2009-05-27 20:00:00  1699.244398          1699.244398  0.078669   \n        2009-05-28 05:00:00  5632.120064          7238.295521  0.173831   \n        2009-05-28 08:00:00  5643.314949          1682.777895  0.522529   \n        2009-05-28 14:00:00    32.131494          1697.111327  0.001488   \n\n                             Acceleration          Jerk     Bearing  \\\ntraj_id DateTime                                                      \n91732   2009-05-27 14:00:00           NaN           NaN         NaN   \n        2009-05-27 20:00:00           NaN           NaN  187.236713   \n        2009-05-28 05:00:00      0.000003           NaN  208.929407   \n        2009-05-28 08:00:00      0.000032  2.717572e-09   28.716637   \n        2009-05-28 14:00:00     -0.000024 -2.611536e-09  123.620959   \n\n                             Bearing_Rate  Rate_of_bearing_rate  \ntraj_id DateTime                                                 \n91732   2009-05-27 14:00:00           NaN                   NaN  \n        2009-05-27 20:00:00           NaN                   NaN  \n        2009-05-28 05:00:00      0.000670              0.000670  \n        2009-05-28 08:00:00     -0.016686             -0.016686  \n        2009-05-28 14:00:00      0.004394              0.004394  ",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th></th>\n      <th>event-id</th>\n      <th>visible</th>\n      <th>lon</th>\n      <th>lat</th>\n      <th>sensor-type</th>\n      <th>individual-taxon-canonical-name</th>\n      <th>individual-local-identifier</th>\n      <th>study-name</th>\n      <th>Distance</th>\n      <th>Distance_from_start</th>\n      <th>Speed</th>\n      <th>Acceleration</th>\n      <th>Jerk</th>\n      <th>Bearing</th>\n      <th>Bearing_Rate</th>\n      <th>Rate_of_bearing_rate</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th>DateTime</th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th rowspan=\"5\" valign=\"top\">91732</th>\n      <th>2009-05-27 14:00:00</th>\n      <td>1082620685</td>\n      <td>True</td>\n      <td>24.58617</td>\n      <td>61.24783</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-27 20:00:00</th>\n      <td>1082620686</td>\n      <td>True</td>\n      <td>24.58217</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>1699.244398</td>\n      <td>1699.244398</td>\n      <td>0.078669</td>\n      <td>NaN</td>\n      <td>NaN</td>\n      <td>187.236713</td>\n      <td>NaN</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 05:00:00</th>\n      <td>1082620687</td>\n      <td>True</td>\n      <td>24.53133</td>\n      <td>61.18833</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5632.120064</td>\n      <td>7238.295521</td>\n      <td>0.173831</td>\n      <td>0.000003</td>\n      <td>NaN</td>\n      <td>208.929407</td>\n      <td>0.000670</td>\n      <td>0.000670</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 08:00:00</th>\n      <td>1082620688</td>\n      <td>True</td>\n      <td>24.58200</td>\n      <td>61.23283</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>5643.314949</td>\n      <td>1682.777895</td>\n      <td>0.522529</td>\n      <td>0.000032</td>\n      <td>2.717572e-09</td>\n      <td>28.716637</td>\n      <td>-0.016686</td>\n      <td>-0.016686</td>\n    </tr>\n    <tr>\n      <th>2009-05-28 14:00:00</th>\n      <td>1082620689</td>\n      <td>True</td>\n      <td>24.58250</td>\n      <td>61.23267</td>\n      <td>gps</td>\n      <td>Larus fuscus</td>\n      <td>91732A</td>\n      <td>Navigation experiments in lesser black-backed ...</td>\n      <td>32.131494</td>\n      <td>1697.111327</td>\n      <td>0.001488</td>\n      <td>-0.000024</td>\n      <td>-2.611536e-09</td>\n      <td>123.620959</td>\n      <td>0.004394</td>\n      <td>0.004394</td>\n    </tr>\n  </tbody>\n</table>\n</div>"
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now lets calculate the rate of bearing rate for the seagulls\n",
    "# dataset.\n",
    "gulls = spatial.create_rate_of_br_column(gulls)\n",
    "gulls.head()"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 375 ms, sys: 160 ms, total: 535 ms\n",
      "Wall time: 3.78 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "           lat   lon\ntraj_id             \nAL031860  40.0 -50.5\nAL011858  19.0 -85.5\nAL011870  30.5 -88.0\nAL021851  22.2 -97.6\nAL051865  29.7 -92.0\n...        ...   ...\nAL041957  13.0 -21.3\nAL142012  15.5 -38.0\nAL201969  16.0 -47.0\nAL141971  25.5 -71.5\nAL031899  11.7 -31.0\n\n[1814 rows x 2 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>lat</th>\n      <th>lon</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th></th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>AL031860</th>\n      <td>40.0</td>\n      <td>-50.5</td>\n    </tr>\n    <tr>\n      <th>AL011858</th>\n      <td>19.0</td>\n      <td>-85.5</td>\n    </tr>\n    <tr>\n      <th>AL011870</th>\n      <td>30.5</td>\n      <td>-88.0</td>\n    </tr>\n    <tr>\n      <th>AL021851</th>\n      <td>22.2</td>\n      <td>-97.6</td>\n    </tr>\n    <tr>\n      <th>AL051865</th>\n      <td>29.7</td>\n      <td>-92.0</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>AL041957</th>\n      <td>13.0</td>\n      <td>-21.3</td>\n    </tr>\n    <tr>\n      <th>AL142012</th>\n      <td>15.5</td>\n      <td>-38.0</td>\n    </tr>\n    <tr>\n      <th>AL201969</th>\n      <td>16.0</td>\n      <td>-47.0</td>\n    </tr>\n    <tr>\n      <th>AL141971</th>\n      <td>25.5</td>\n      <td>-71.5</td>\n    </tr>\n    <tr>\n      <th>AL031899</th>\n      <td>11.7</td>\n      <td>-31.0</td>\n    </tr>\n  </tbody>\n</table>\n<p>1814 rows × 2 columns</p>\n</div>"
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the start locations of all the trajectories\n",
    "# in the atlantic dataset.\n",
    "spatial.get_start_location(atlantic)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 31.9 ms, sys: 4.52 ms, total: 36.4 ms\n",
      "Wall time: 34.3 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "(31.0, -100.2)"
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the end location of a specific trajectory\n",
    "# from the atlantic dataset.\n",
    "spatial.get_end_location(atlantic, 'AL011851')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 30.7 ms, sys: 3.75 ms, total: 34.5 ms\n",
      "Wall time: 32.7 ms\n"
     ]
    },
    {
     "data": {
      "text/plain": "716547.1062403042"
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the distance travelled by a specific trajectory\n",
    "# in the atlantic dataset.\n",
    "spatial.get_distance_travelled_by_traj_id(atlantic, 'AL011851')"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "CPU times: user 421 ms, sys: 169 ms, total: 589 ms\n",
      "Wall time: 3.54 s\n"
     ]
    },
    {
     "data": {
      "text/plain": "          Number of Unique Coordinates\ntraj_id                               \nAL031860                             1\nAL011858                             1\nAL011870                             1\nAL021851                             1\nAL051865                             1\n...                                ...\nAL041957                            95\nAL142012                            96\nAL201969                            99\nAL141971                           118\nAL031899                           133\n\n[1814 rows x 1 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Number of Unique Coordinates</th>\n    </tr>\n    <tr>\n      <th>traj_id</th>\n      <th></th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>AL031860</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>AL011858</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>AL011870</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>AL021851</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>AL051865</th>\n      <td>1</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>AL041957</th>\n      <td>95</td>\n    </tr>\n    <tr>\n      <th>AL142012</th>\n      <td>96</td>\n    </tr>\n    <tr>\n      <th>AL201969</th>\n      <td>99</td>\n    </tr>\n    <tr>\n      <th>AL141971</th>\n      <td>118</td>\n    </tr>\n    <tr>\n      <th>AL031899</th>\n      <td>133</td>\n    </tr>\n  </tbody>\n</table>\n<p>1814 rows × 1 columns</p>\n</div>"
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# Now, lets get the number of unique locations visited by\n",
    "# all the trajectories in the atlantic dataset.\n",
    "spatial.get_number_of_locations(atlantic)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total execution time is 38.94007086753845 seconds.\n"
     ]
    }
   ],
   "source": [
    "end = time.time()\n",
    "print(f\"Total execution time is {end - start} seconds.\")"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}